package com.wms.controller;

import com.wms.entity.File;
import com.wms.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/files")
public class FileController {

    @Autowired
    private FileService fileService;

    @GetMapping("/{id}")
    public ResponseEntity<File> getFileById(@PathVariable Integer id) {
        File file = fileService.getFileById(id);
        return ResponseEntity.ok(file);
    }

    @GetMapping
    public ResponseEntity<List<File>> getAllFiles() {
        List<File> files = fileService.getAllFiles();
        return ResponseEntity.ok(files);
    }

    @PostMapping
    public ResponseEntity<Boolean> addFile(@RequestBody File file) {
        boolean result = fileService.addFile(file);
        return ResponseEntity.ok(result);
    }

    @PutMapping("/{id}")
    public ResponseEntity<Boolean> updateFile(@PathVariable Integer id, @RequestBody File file) {
        file.setId(id);
        boolean result = fileService.updateFile(file);
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteFile(@PathVariable Integer id) {
        boolean result = fileService.deleteFile(id);
        return ResponseEntity.ok(result);
    }

    @GetMapping("/not-deleted")
    public ResponseEntity<List<File>> getNotDeletedFiles() {
        List<File> files = fileService.getNotDeletedFiles();
        return ResponseEntity.ok(files);
    }

    @PutMapping("/soft-delete/{id}")
    public ResponseEntity<Boolean> softDeleteFile(@PathVariable Integer id) {
        boolean result = fileService.softDeleteFile(id);
        return ResponseEntity.ok(result);
    }
}
